package com.friday.util;

import java.sql.Time;

import com.friday.dao.MessageDao;
import com.friday.dao.impl.MessageDaoImpl;
import com.friday.po.Message;

public class MessageUtil {
	private MessageDao md = new MessageDaoImpl();
	private static MessageUtil mtil = null;
	
	public static MessageUtil newInstance() throws Exception {
		synchronized (DBUtil.class) {
			if (mtil == null) {
				mtil = new MessageUtil();
			}
		}

		return mtil;
	}
	public int sendMessage(String from,String to,String title,String content)
	{
		Time time = new Time(System.currentTimeMillis());
		Message m = new Message();
		int num = 0;
		try {
			m.setId();
			m.setSender(from);
			m.setReceiver(to);
			m.setTitle(title);
			m.setContent(content);
			m.setTime(time);
			m.setState(0);
			md.insertMessage(m);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return num;
	}

}
